package com.youpai.platform.vulture.service.facade;

import com.youpai.platform.vulture.common.entity.AccessMessage;
import com.youpai.platform.vulture.service.channel.VultureChannel;
import com.youpai.platform.vulture.service.entity.dto.ReceiveMessageDTO;
import com.youpai.platform.vulture.service.entity.dto.SendMessageDTO;
import com.youpai.platform.vulture.service.support.VultureChannelSupport;
import com.youpai.platform.vulture.service.util.MessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @date: 2022/7/10 23:18
 * @author: Anna
 * @version: 1.0
 * @description: 消息门面类
 */
@Slf4j
@Component
public class VultureVultureMessageFacade implements VultureMessageFacadeInterface {

    @Override
    public void sendMessage(SendMessageDTO sendMessageDTO) {
        VultureChannel toVultureChannel = VultureChannelSupport.getVultureChannelByAccId(sendMessageDTO.getToAccId());
        if (null == toVultureChannel) {
            log.info("接收方不在线");
            return;
        }
        AccessMessage accessMessage = MessageUtil.buildC2CAccessMessage(sendMessageDTO.getBody(), sendMessageDTO.getCmd());
        toVultureChannel.send(accessMessage);
    }
}
